package com.viser.partyinrs.adapters;

import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;

import com.viser.partyinrs.entities.Dogadjaj;
import com.viser.partyinrs.http.HttpDispatcher;

public class DogadjajAdapter extends DataAdapter {
	
	public DogadjajAdapter ()
	{
		dispatcher = new HttpDispatcher();
	}
	
	@SuppressWarnings("finally")
	public ArrayList<Dogadjaj> getDogadjaj (){
		ArrayList<Dogadjaj> dogadjaji = new ArrayList<Dogadjaj>();
		try {
			String httpResponse = dispatcher.getHttpResponse_GET(pageBase+"dogadjaji_list.php?upit=upit");
			JSONArray dogadjajArray = new JSONArray(httpResponse);
			for (int i = 0; i < dogadjajArray.length(); i++) {
				JSONObject dogadjaj = dogadjajArray.getJSONObject(i);
				Dogadjaj d = new Dogadjaj();
				d.idMesto = dogadjaj.getInt("id_mesto");
				d.redniBroj = dogadjaj.getInt("rb");
				d.naziv = dogadjaj.getString("naziv");
				d.opis = dogadjaj.getString("opis");
				d.urlSlika = dogadjaj.getString("url_slika");
				d.vremePocetak = dogadjaj.getString("vreme_od");
				d.vremeKraj = dogadjaj.getString("vreme_do");
			}
			
		}
		catch (Exception ex) { }
		finally
		{
			return dogadjaji;
		}
	}

}
